//
//  SKMainFunctionViewController.m
//  Gastrosoph
//
//  Created by 张明磊 on 12-10-18.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "SKMainFunctionViewController.h"
#import "SKRevealSideViewController.h"

CGFloat SKFunctionImage_CGRectWidth  = 253;

CGFloat SKFunctionImage_CGRectHeight  = 97;

CGFloat SKFunctionButton_CGRectWidth = 127;

CGFloat SKFunctionButton_CGRectHeight = 91;


typedef enum
{
    SKButtonTag_topRank     = 0,
    SKButtonTag_nearby         ,
    SKButtonTag_theme          ,
    SKButtonTag_search         ,
    SKButtonTag_myInformation  ,
    SKButtonTag_returnToMain   ,
    
}SKMainFunction_button_tag;


@interface SKMainFunctionViewController ()

@end

@implementation SKMainFunctionViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self install_view_title];
    
    [self install_view_functionButton];
    
    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"mainFunctionBackground.png"]]];
    
	// Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


#pragma mark - 
#pragma mark InstallView

- (void)install_view_title
{
    UIImageView *image_title = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image_functionTitle.png"]];
    
    [image_title setFrame:CGRectMake(0, 0, SKFunctionImage_CGRectWidth, SKFunctionImage_CGRectHeight)];
    
    [self.view addSubview:image_title];
    
    [image_title release];
}


- (void)install_view_functionButton
{
    UIButton *button_topRank = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button_topRank setFrame:CGRectMake(0, SKFunctionImage_CGRectHeight, SKFunctionButton_CGRectWidth, SKFunctionButton_CGRectHeight)];
    
    [button_topRank setBackgroundImage:[UIImage imageNamed:@"button_topRank.png"] forState:UIControlStateNormal];
    
    [button_topRank setBackgroundImage:[UIImage imageNamed:@"button_topRank_pressed.png"] forState:UIControlStateHighlighted];
    
    [button_topRank setTag:SKButtonTag_topRank];
    
    [button_topRank addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button_topRank];
    
    UIButton *button_nearby = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button_nearby setFrame:CGRectMake(SKFunctionButton_CGRectWidth, SKFunctionImage_CGRectHeight, SKFunctionButton_CGRectWidth, SKFunctionButton_CGRectHeight)];
    
    [button_nearby setBackgroundImage:[UIImage imageNamed:@"button_nearby.png"] forState:UIControlStateNormal];
    
    [button_nearby setBackgroundImage:[UIImage imageNamed:@"button_nearby_pressed.png"] forState:UIControlStateHighlighted];
    
    [button_nearby setTag:SKButtonTag_nearby];
    
    [button_nearby addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button_nearby];
    
    UIButton *button_theme = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button_theme setFrame:CGRectMake(0, SKFunctionImage_CGRectHeight + SKFunctionButton_CGRectHeight, SKFunctionButton_CGRectWidth, SKFunctionButton_CGRectHeight)];
    
    [button_theme setBackgroundImage:[UIImage imageNamed:@"button_theme.png"] forState:UIControlStateNormal];
    
    [button_theme setBackgroundImage:[UIImage imageNamed:@"button_theme_pressed.png"] forState:UIControlStateHighlighted];
    
    [button_theme setTag:SKButtonTag_theme];
    
    [button_theme addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button_theme];
    
    UIButton *button_search = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button_search setFrame:CGRectMake(SKFunctionButton_CGRectWidth, SKFunctionImage_CGRectHeight + SKFunctionButton_CGRectHeight, SKFunctionButton_CGRectWidth, SKFunctionButton_CGRectHeight)];
    
    [button_search setBackgroundImage:[UIImage imageNamed:@"button_search.png"] forState:UIControlStateNormal];
    
    [button_search setBackgroundImage:[UIImage imageNamed:@"button_search_pressed.png"] forState:UIControlStateHighlighted];
    
    [button_search setTag:SKButtonTag_search];
    
    [button_search addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button_search];
    
    UIButton *button_myInformaton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button_myInformaton setFrame:CGRectMake(0, SKFunctionImage_CGRectHeight + (SKFunctionButton_CGRectHeight * 2), SKFunctionButton_CGRectWidth, SKFunctionButton_CGRectHeight)];
    
    [button_myInformaton setBackgroundImage:[UIImage imageNamed:@"button_myInformation.png"] forState:UIControlStateNormal];
    
    [button_myInformaton setBackgroundImage:[UIImage imageNamed:@"button_myInformation_pressed.png"] forState:UIControlStateHighlighted];
    
    [button_myInformaton setTag:SKButtonTag_myInformation];
    
    [button_myInformaton addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button_myInformaton];
    
    UIButton *button_returnToMain = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button_returnToMain setFrame:CGRectMake(SKFunctionButton_CGRectWidth, SKFunctionImage_CGRectHeight + (SKFunctionButton_CGRectHeight * 2), SKFunctionButton_CGRectWidth, SKFunctionButton_CGRectHeight)];
    
    [button_returnToMain setBackgroundImage:[UIImage imageNamed:@"button_returnToMain.png"] forState:UIControlStateNormal];
    
    [button_returnToMain setBackgroundImage:[UIImage imageNamed:@"button_returnToMain_pressed.png"] forState:UIControlStateHighlighted];
    
    [button_returnToMain setTag:SKButtonTag_returnToMain];
    
    [button_returnToMain addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button_returnToMain];
}


- (void)didClickButton:(id)sender
{
    UIButton *button_tmp = (UIButton *)sender;
    
    switch (button_tmp.tag) 
    {
        case SKButtonTag_topRank:
        {
            break;
        }
        case SKButtonTag_nearby:
        {
            break;
        }
        case SKButtonTag_theme:
        {
            break;
        }
        case SKButtonTag_search:
        {
            break;
        }
        case SKButtonTag_myInformation:
        {
            break;
        }
        case SKButtonTag_returnToMain:
        {
            [self.revealSideViewController pushOldViewControllerOnDirection:PPRevealSideDirectionLeft withOffset:68.0 animated:YES];
            
            break;
        }
        default:
            break;
    }
}


@end
